package cn.tedu.tmall.passport.controller;

import cn.tedu.tmall.common.pojo.authentication.CurrentPrincipal;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

@Api(tags = "测试登录")
@RestController
@RequestMapping("/test")
public class TestSecurityController {
    @ApiOperation("不需要验证登录")
    @ApiOperationSupport(order = 100)
    @GetMapping("/permit")
    public String permit(){
        return "成功处理请求，不需要验证登录";
    }

    @ApiOperation("需要验证登录")
    @ApiOperationSupport(order = 101)
    @GetMapping("/authenticated")
    public String authenticated(){
        return "成功处理请求，需要验证登录";
    }

    @ApiOperation("识别当事人")
    @ApiOperationSupport(order = 102)
    @GetMapping("/principal")
    public String authenticated(@ApiIgnore @AuthenticationPrincipal CurrentPrincipal principal){
        return "登陆成功，当事人是："+principal;
    }

    @ApiOperation("需要某个权限")
    @PreAuthorize("hasAuthority('/account/create')")
    @ApiOperationSupport(order = 103)
    @GetMapping("/authority")
    public String hasAuthority(){
        return "成功处理请求，需要某个权限";
    }
}
